/*
 * Copyright (c) 2006, 2022, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.Arrays;

/**
 * <p>Project: javase202202 - Arr8
 * <p>Powered by Lisi On 2022-06-06 10:08:47
 * <p>Created by IntelliJ IDEA
 *

 * @version 1.0
 * @since 17
 */
public class Arr8 {
    public static void main(String[] args) {
        Student[] sts = new Student[]{
                new Student(100, "李四", 80),
                new Student(200, "张三", 88),
                new Student(300, "王五", 90),
                new Student(400, "赵六", 92),
                new Student(500, "张三丰", 30),
                new Student(600, "周强", 20)
        };

        //System.out.println(Arrays.toString(sts));
        for(Student s : sts){
            System.out.printf("ID:%d，姓名：%s，成绩：%d分。%n",s.getId(),s.getName(),s.getScore());
        }

        System.out.println("-".repeat(50));
        //根据学生对象的成绩，降序
        Arrays.sort(sts,(a,b)->b.getScore()-a.getScore());
        for(Student s : sts){
            System.out.printf("姓名：%s，成绩：%d分。%n",s.getName(),s.getScore());
        }


        System.out.println("-".repeat(50));
        //根据学生对象的姓名排序
        Arrays.sort(sts,(a,b)->a.getName().compareTo(b.getName()));
        for(Student s : sts){
            System.out.printf("姓名：%s，成绩：%d分。%n",s.getName(),s.getScore());
        }


    }
}
